package com.ruoyi.sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sale.domain.MallHomeNewProduct;
import com.ruoyi.sale.service.IMallHomeNewProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新鲜好物Controller
 *
 * @author cws
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/sale/newProduct")
public class MallHomeNewProductController extends BaseController {
    @Autowired
    private IMallHomeNewProductService mallHomeNewProductService;

    /**
     * 查询新鲜好物列表
     */
    @PreAuthorize("@ss.hasPermi('sale:newProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallHomeNewProduct mallHomeNewProduct) {
        startPage();
        List<MallHomeNewProduct> list = mallHomeNewProductService.selectMallHomeNewProductList(mallHomeNewProduct);
        return getDataTable(list);
    }

    /**
     * 导出新鲜好物列表
     */
    @PreAuthorize("@ss.hasPermi('sale:newProduct:export')")
    @Log(title = "新鲜好物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallHomeNewProduct mallHomeNewProduct) {
        List<MallHomeNewProduct> list = mallHomeNewProductService.selectMallHomeNewProductList(mallHomeNewProduct);
        ExcelUtil<MallHomeNewProduct> util = new ExcelUtil<MallHomeNewProduct>(MallHomeNewProduct.class);
        util.exportExcel(response, list, "新鲜好物数据");
    }

    /**
     * 获取新鲜好物详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:newProduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mallHomeNewProductService.selectMallHomeNewProductById(id));
    }

    /**
     * 新增新鲜好物
     */
    @PreAuthorize("@ss.hasPermi('sale:newProduct:add')")
    @Log(title = "新鲜好物", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallHomeNewProduct mallHomeNewProduct) {
        return toAjax(mallHomeNewProductService.insertMallHomeNewProduct(mallHomeNewProduct));
    }


    /**
     * 批量新增新鲜好物
     */
    @PreAuthorize("@ss.hasPermi('sale:newProduct:add')")
    @Log(title = "批量新鲜好物", businessType = BusinessType.INSERT)
    @PostMapping("/batchSave")
    public AjaxResult add(@RequestBody List<MallHomeNewProduct> mallHomeNewProducts) {
        return toAjax(mallHomeNewProductService.BatchInsertMallHomeNewProduct(mallHomeNewProducts));
    }


    /**
     * 修改新鲜好物
     */
    @PreAuthorize("@ss.hasPermi('sale:newProduct:edit')")
    @Log(title = "新鲜好物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallHomeNewProduct mallHomeNewProduct) {
        return toAjax(mallHomeNewProductService.updateMallHomeNewProduct(mallHomeNewProduct));
    }

    /**
     * 删除新鲜好物
     */
    @PreAuthorize("@ss.hasPermi('sale:newProduct:remove')")
    @Log(title = "新鲜好物", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mallHomeNewProductService.deleteMallHomeNewProductByIds(ids));
    }
}
